/*
 * Used for AK/SK Signature Authentication.
 *
 * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */
#ifndef __SIGNER_H
#define __SIGNER_H

#include "signer_common.h"

#define SIG_MEMORY_ALLOCATION_ERROR  (-2)
#define SIG_INVALID_INPUT_ERROR      (-1)
#define SIG_OK                        0

#define DATE_MAX_LEN                 20

typedef struct sig_header_s {
    sig_str_t name;
    sig_str_t value;
} sig_header_t;

typedef struct sig_headers_s {
    sig_header_t *data;
    size_t len;
    size_t alloc;
} sig_headers_t;

sig_header_t *sig_headers_get(const sig_headers_t *headers, const char *header_name);

sig_header_t *sig_headers_add(sig_headers_t *headers, const char *header_name,
                              const char *header_value);

void sig_headers_free(sig_headers_t *headers);

typedef struct sig_params_s {
    /* credential parameters */
    sig_str_t key;
    sig_str_t secret;
    /* HTTP request parameters */
    sig_str_t method;
    sig_str_t uri;
    sig_str_t uri_prefix;
    sig_str_t query_str;
    sig_str_t host;
    sig_headers_t headers;
    sig_str_t payload;
} sig_params_t;

void sig_params_init(sig_params_t *sig_params);

void sig_params_free(sig_params_t *sig_params);

int sig_sign(sig_params_t *sig_params);

#endif
